package org.cycuchy.hp.components.book.places {
	
	import mx.controls.Image;
	import mx.core.BitmapAsset;
	import mx.events.FlexEvent;
	
	import org.cycuchy.hp.components.book.NumeredPage;
	
	import qs.containers.Landscape;
	import qs.graphics.Hilight;

	public class PlacesPage_code extends NumeredPage {
		
        [Embed(source='assets/embed/img/places.jpg')]
		private static const placesImageClass:Class;
		
		private var _items:Array = null;
		
		public var viewer:Landscape;
		
		private var polaroid:Image;
		
		public function PlacesPage_code() {
			super();
			_items = new Array();
			addEventListener(FlexEvent.CREATION_COMPLETE, creationComplete);			
		}
		
		private function creationComplete(event:FlexEvent):void {
			removeEventListener(FlexEvent.CREATION_COMPLETE, creationComplete);
			var bitmapAsset:BitmapAsset = BitmapAsset(new placesImageClass());
			polaroid = new Image();
			polaroid.source = bitmapAsset;
			_items.push(polaroid);
//			viewer.children = [polaroid];
			view(polaroid);
		}
		
		public function set items(items:Array):void {
			//_items = items;
			
			var c:Hilight;
			var item:Object;
			//for each (var item:Object in items) {
			for (var i:uint=1; i<items.length; i++) {
				item = items[i];
				c = new Hilight();
				c.x = item.x;
				c.y = item.y;
				c.width = item.width;
				c.height = item.height;
				_items.push(c); 
			}
			viewer.children = _items;
		}
		
		internal function f(i:uint):void {
//			trace("f: ", i);
			view(_items[i]);
		}
		
		private function view(...targets:Array):void {
//			viewer.selection = targets;
			for each (var sel:Object in viewer.selection) {
				if (sel is Hilight) {
					Hilight(sel).currentState = null;	
				}
			}
			viewer.selection = targets;
			for each (sel in viewer.selection) {
				if (sel is Hilight) {
					Hilight(sel).currentState = "selected";	
				}
			}
		} 
		
	}
	
}